Lab 3 & 4

Classroom distribution

Important Reminders

  • Get involved! Watching others work can lead you to believe you understand when in fact you don’t.
  • Make sure to give others an opportunity to express themselves.
  • If needed, and wanted, help other groups, but don’t do things for them.
  • Discuss the problems respectfully.

Lab 3

Lab topics:

Distribution Functions

  • Distributions
  • R Commands

An example: Standard Normal distribution

  • Generate samples: rnorm(n),
  • \(f_X(x) = P(X = x):\) dnorm(x)
  • \(F_X(x)= P(X \leq x):\) pnorm(x) and
  • \(F^{-1}_X(q)\) qnorm(q) .

An example: Standard Normal distribution

Generate samples: rnorm(30), dnorm(1.65), pnorm(1.65) and qnorm(0.85) .

Lab 3

Hints and advises:

  • Consider the parameters required for the corresponding distribution.

  • An expression for a probability can look like one of the following: \(P(a < X < b)\), \(P(a \leq X \leq b)\), \(P(a \leq X < b)\), \(P(a < X)\), \(P(a \leq X)\), \(P(a > X)\), \(P(a \geq X)\), etc.

  • Remember the plotting function hist and curve.

Lab 3

Hints and advises:

  • Remember the plotting function hist and curve.
Code
a <- 10 # minimum
b <- 25 # maximum
x <- runif(n = 10000, min = a, max = b)
hist(x, prob = T)
curve(dunif(x, min = a, max = b),
  from = a, to = b, add = T,
  col = "red"
)

Lab 4

Lab topic:

Minimum and Maximum of Independent Random Variables

Hints and advises:

  • Note that the notation is graded, so be mindful of it.

Lab 4

Hints and advises:

  • You can use r<dist> to simulate.
Code
n <- 1000
Xa <- rexp(n, rate = 1 / 40)
Xb <- rexp(n, rate = 1 / 50)
  • And create another r.v. from it.
Code
X <- cbind(Xa, Xb) # Matrix n*2
Y1 <- apply(X, 1, max) # Vector w/ n obs.

Lab 4

Hints and advises:

  • You can create your own functions and plot them.
Code
hist(Y1, prob = T, breaks = 40) # draw a histogram
# define a function of the pdf in Section 1.1
f1 <- function(y) {
  1 / 40 * exp(-y / 40) + 1 / 50 * exp(-y / 50) - 9 / 200 * exp(-9 * y / 200)
}
# draw a curve based on the above function and add it to the histogram
curve(f1, from = 0, to = 350, add = T, col = "red")